package com.huiren.util;

import java.lang.reflect.Method;

public class SetUtil {

	public static void getter(Object obj, String att) {
		att = toUpperCaseFirstOne(att);
		try {
			Method method = obj.getClass().getMethod("get" + att);
			System.out.println(method.invoke(obj));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void setter(Object obj, String att, Object value,
			Class<?> type) {
		att = toUpperCaseFirstOne(att);
		try {
			Method method = obj.getClass().getMethod("set" + att, type);
			method.invoke(obj, value);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static String toUpperCaseFirstOne(String s) {
		if (Character.isUpperCase(s.charAt(0)))
			return s;
		else
			return (new StringBuilder())
					.append(Character.toUpperCase(s.charAt(0)))
					.append(s.substring(1)).toString();
	}

}
